using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using Entities;
using Utility;

namespace BUS
{
    public class tbKhachhangBUS
    {
        public static void Insert(tbKhachhang kh)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Insert(kh);
        }
        public static void Update(tbKhachhang kh)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Update(kh);
        }
        public static void Delete(int iD)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            khDAL.Delete(iD);
        }
        public static tbKhachangCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbKhachangCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 0, 0, tbKhachhanhColumn.Makh.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbKhachhang GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbKhachhanhColumn.Makh.ToString(), Condition.EQUAL, iD);
           tbKhachhangDAL khDAL = new tbKhachhangDAL();
            tbKhachangCollection tbkhachangCollection = khDAL.Get(cri.Criter, 0, 0, tbKhachhanhColumn.Makh.ToString(), OrderDirection.ASC.ToString(), out total);
            if (tbkhachangCollection.Count > 0)
                return tbkhachangCollection[0];
            return null;
        }
        public static tbKhachangCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 1, number, tbKhachhanhColumn.Makh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbKhachangCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.Get(cri.Criter, 1, number,
               tbKhachhanhColumn.Makh.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbKhachhang GetByEmail(String em)
        {
            tbKhachhangDAL khDAL = new tbKhachhangDAL();
            return khDAL.GetByEmail(em);
        }
        //public static tbKhachhang GetTendangnhap(string tdn)
        //{
        //    tbKhachhangDAL khDAL = new tbKhachhangDAL();
        //    return khDAL.GetByTendangnhap(tdn);
        //}
    }
}
